package com.crm.service.impl.opportunityManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customMapper.opportunityManagerCustomMapper.PhraseCustomMapper;
import com.crm.dao.mapper.opportunityManager.OpportunityDynamicMapper;
import com.crm.dao.mapper.opportunityManager.PhraseMapper;
import com.crm.model.entity.opportunityManager.OpportunityDynamic;
import com.crm.model.entity.opportunityManager.OpportunityDynamicExample;
import com.crm.model.entity.opportunityManager.Phrase;
import com.crm.model.entity.opportunityManager.PhraseExample;
import com.crm.service.opportunityManager.OpportunityDynamicDbService;
import com.crm.service.opportunityManager.OpportunityPhraseDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 常用语
 */
@Service
public class OpportunityPhraseDbServiceImpl implements OpportunityPhraseDbService {

    @Autowired
    private PhraseMapper phraseMapper;

    @Autowired
    private PhraseCustomMapper phraseCustomMapper;

    /**
     * 商机-商机详情-常用语展示
     * @return
     */
    @Override
    public List<Phrase> phraseList(String accountId) {
        PhraseExample phraseExample = new PhraseExample();
        phraseExample.setOrderByClause("phrase_order asc");
        PhraseExample.Criteria criteria = phraseExample.createCriteria();
        criteria.andCreatePeopleIdEqualTo(accountId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<Phrase> list = phraseMapper.selectByExample(phraseExample);
        return list;
    }

    /**
     * 商机管理-新增跟进常用语
     * @param phrase 常用语实体
     * @return
     */
    @Override
    public Boolean addPhrase(Phrase phrase) {
        Boolean result = false;
        int num = phraseMapper.insertSelective(phrase);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 商机-商机详情-修改常用语回显
     * @param phraseId 常用语id
     * @return
     */
    @Override
    public Phrase getPhraseById(String phraseId) {
        return phraseMapper.selectByPrimaryKey(phraseId);
    }

    /**
     * 商机管理-修改常用语
     * @param phrase 常用语实体
     * @return
     */
    @Override
    public Boolean updatePhrase(Phrase phrase) {
        Boolean result = false;
        int num = phraseMapper.updateByPrimaryKeySelective(phrase);
        if(num>0){
            result = true;
        }
        return result;
    }

    /**
     * 把常用语改为删除状态
     * @param delPhrase 常用语信息
     * @return
     */
    @Override
    public Boolean updateCustomPhrase(Phrase delPhrase) {
        Boolean result = false;
        int num = phraseCustomMapper.updatePhrase(delPhrase);
        if(num>0){
            result = true;
        }
        return result;
    }
}
